﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;

namespace tPlat
{
    public class HotelSystem
    {
        private string date;
        private string time;
        private List<User> users = new List<User>();
        private Database database;

        public HotelSystem()
        {
            this.database = new Database("Hotel");
        }

        public string getTime()
        {
            throw new System.NotImplementedException();
        }
        public string getDate()
        {
            throw new System.NotImplementedException();
        }

        public Database getDatabase()
        {
            return this.database;
        }
        public User loginUser(string username, string password)
        {
            string select = "SELECT * FROM Users WHERE login='" + username + "' AND password='" + password+"'";
            DataSet dsUsers = new DataSet();
            SqlDataAdapter daUsers = new SqlDataAdapter(select, database.getConnection());
            daUsers.Fill(dsUsers, "Users");
            DataTable usersTable = dsUsers.Tables["Users"];
            if (usersTable.Rows.Count == 1)
            {
                DataRow row = usersTable.Rows[0];
                if (row["status"].ToString() == "0")
                {
                    Admin a = new Admin(row["login"].ToString(), row["password"].ToString(), row["id"].ToString());
                    users.Add(a);
                    return a;
                }
                else
                {
                    User u = new User(row["login"].ToString(), row["password"].ToString(), row["id"].ToString());
                    users.Add(u);
                    return u;
                }
            }
            else
            {
                //logged = false;
                return new User("", "", "");
            }
        }
        public void logoutUser(User usr)
        {
            users.Remove(usr);
        }
    }
}
